#include <map>
#include <string>
#include <iostream>
#include <vector>
#include <list>

class A {
public:
	int m;
	A() {
		m = 0;
	}
	~A() = default;
	A(const A& rth) {

	}
};

template<typename T, size_t N>
class B {
public:
	T m_elements[N];
	B() {
		for (size_t i = 0;i < N;i++) {
			m_elements[i] = i;
		}
	}
	~B() = default;

	T* begin() {
		return m_elements + 0;
	}
	T* end() {
		return m_elements + N;
	}
};
class C {
public:
	int m;
	C(int value) {
		m = value;
	}
	~C() = default;
	C(const C& rth) {
		if (this == &rth)return;

		this->m = rth.m;
		std::cout << "Test copy-constructed" << std::endl;
	}
};

void LogMap() {
	std::map<std::string, std::string> seasons;
	seasons["spring"] = "345";
	seasons["summer"] = "678";
	seasons["autumn"] = "91011";
	seasons["winter"] = "1212";

	/*for (auto iter = seasons.begin(); iter != seasons.end();iter++) {
		std::cout << iter->second << std::endl;
	}*/
	/*for (auto& iter : seasons) {
		iter.second = "HHHH";
	}*/
	for (auto iter : seasons) {
		std::cout << iter.second << std::endl;
	}
}

void LogVector() {
	std::vector<std::string> v;
	v.push_back("zhangsan");
	v.push_back("lisi");
	v.push_back("wangwu");
	v.push_back("liliu");
	for (auto iter = v.begin(); iter != v.end();iter++) {
		*iter = "hello";
	}
	/*for (auto& iter : v) {
		iter = "hello";
	}*/
	for (auto& iter : v) {
		std::cout << iter << std::endl;
	}

	A a1;
	A a2;
	A a3;
	std::vector<A> v2;
	v2.push_back(a1);
	v2.push_back(a2);
	v2.push_back(a3);
	for (auto iter = v2.begin(); iter != v2.end();iter++) {
		iter->m = 1;
	}
	//for (auto& iter : v2) {
	//	iter.m = 1;
	//}
	/*for (int i = 0; i < v2.size(); ++i) {
		v2[i].m = 5;
	}*/
	for (auto& iter : v2) {
		std::cout << iter.m << std::endl;
	}
}

class ChatDialog {
public:
	ChatDialog() {
		std::cout << "ChatDialog contructor" << std::endl;
	}
	~ChatDialog() {
		std::cout << "ChatDialog destructor" << std::endl;
	}
public:
	void activate() {

	}
};

std::map<long, std::unique_ptr<ChatDialog>> m_ChatDialogs;
void OnClickItem(long userid)
{
	auto [iter, inserted] = m_ChatDialogs.try_emplace(userid, nullptr);
	if (inserted) {
		auto spChat = std::make_unique<ChatDialog>();
		iter->second = std::move(spChat);

		//std::cout << "inserted" << std::endl;
	}
	iter->second->activate();
}
void LogChatDialog() {

	OnClickItem(1);
	OnClickItem(2);
	OnClickItem(1);

	m_ChatDialogs.clear();
}

void TestLog() {
	
    //LogMap();

	//int arr[10] = { 0 };
	//for (int i : arr) {
	//	std::cout << i << std::endl;
	//}

	//LogVector();

	//B<int, 10>b;
	///*for (auto iter : b) {
	//	std::cout << iter << std::endl;
	//}*/
	//for (auto iter = b.begin();iter < b.end();iter++) {
	//	std::cout << *iter << std::endl;
	//}

	//std::list<C> list;
	//for (int i = 0;i < 10;i++) {
	//	list.emplace_back(i * 2);
	//}
	//for (auto& i : list) {
	//	std::cout << i.m << std::endl;
	//}

	LogChatDialog();

	std::cout << "======================================" << std::endl;
}